package com.smartrobot.smartrobot.pagerHolder;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.smartrobot.smartrobot.R;
import com.smartrobot.smartrobot.activity.ActiveActivity;
import com.smartrobot.smartrobot.activity.EducationActivity;
import com.smartrobot.smartrobot.activity.FashionActivity;
import com.smartrobot.smartrobot.activity.GameAcitivity;
import com.smartrobot.smartrobot.activity.ScheduleActivity;
import com.smartrobot.smartrobot.activity.ProductActivity;
import com.smartrobot.smartrobot.activity.StoreActiveActivity;

public class InformationPagerHolder extends Fragment implements BaseFragment,View.OnClickListener{

    private Context context;
	private View view;
    private boolean isFirst = true;
    private boolean isCreate = false;
    private RelativeLayout product,active,detail,fashion,education,storeActive,game;
	
	public InformationPagerHolder() {
        super();
	}

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    /**
     * 返回的view为滑动显示的view
     * @return
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.page_main_information,container,false);
        isCreate = true;
        init();


        return view;
    }

    @Override
    public void onStart() {

        init();

        super.onStart();
    }

    @Override
    public void init(){


        if(isCreate)
        if(isFirst){
            if(getActivity() == null) throw new NullPointerException();
            isFirst = false;
            product = (RelativeLayout)view.findViewById(R.id.main_information_product);
            active = (RelativeLayout)view.findViewById(R.id.main_information_active);
            detail = (RelativeLayout)view.findViewById(R.id.main_information_detail);
            fashion = (RelativeLayout)view.findViewById(R.id.main_information_fashion);
            education = (RelativeLayout)view.findViewById(R.id.main_information_education);
            storeActive = (RelativeLayout)view.findViewById(R.id.main_information_store);
            game = (RelativeLayout)view.findViewById(R.id.main_information_game);


            product.setOnClickListener(this);
            active.setOnClickListener(this);
            detail.setOnClickListener(this);
            fashion.setOnClickListener(this);
            education.setOnClickListener(this);
            storeActive.setOnClickListener(this);
            game.setOnClickListener(this);
        }


    }


    @Override
    public void onClick(View view) {

        Intent intent = new Intent();

        switch (view.getId()){

            case R.id.main_information_product:
            intent.setClass(getActivity(), ProductActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getActivity().startActivity(intent);

                break;

            case R.id.main_information_active:
                intent.setClass(getActivity(), ActiveActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getActivity().startActivity(intent);
                break;

            case R.id.main_information_detail:
                intent.setClass(getActivity(), ScheduleActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getActivity().startActivity(intent);
                break;


            case R.id.main_information_fashion:
                intent.setClass(getActivity(), FashionActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getActivity().startActivity(intent);
                break;


            case R.id.main_information_education:
                intent.setClass(getActivity(), EducationActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getActivity().startActivity(intent);
                break;

            case R.id.main_information_store:
                intent.setClass(getActivity(), StoreActiveActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getActivity().startActivity(intent);
                break;

            case R.id.main_information_game:
                intent.setClass(getActivity(), GameAcitivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getActivity().startActivity(intent);
                break;


        }

    }


}
